package name.marz.to.go.ahg.mufgbk.executer;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;

import name.marz.to.go.ahg.common.util.HttpUtil;
import name.marz.to.go.ahg.core.AutoGetterHttpClient;
import name.marz.to.go.ahg.core.Parameters;
import name.marz.to.go.ahg.core.checker.DocumentChecker;
import name.marz.to.go.ahg.core.executer.AbstractLoginExecuter;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.jsoup.nodes.Document;

public class MUFGbkLoginExecuter extends AbstractLoginExecuter {
	private static final String FORM_NAME="MainForm";
	private Document srcDoc;
	private DocumentChecker checker = new MUFGbkLoginChecker();

	public MUFGbkLoginExecuter(URI baseUri, AutoGetterHttpClient client, Document srcDoc) {
		super(baseUri, client);
		this.srcDoc = srcDoc;
		super.uri = HttpUtil.createURISafety(baseUri.getScheme()
				, baseUri.getAuthority()
				, HttpUtil.getFormActionString(srcDoc, FORM_NAME));
	}

	@Override
	protected List<NameValuePair> getRequestParameters() {
		Parameters p = HttpUtil.getParametersFromFormTag(srcDoc,FORM_NAME);
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("KEIYAKU_NO", super.userIdentifiers[0]));
		params.add(new BasicNameValuePair("PASSWORD", super.userPass));
		params.add(new BasicNameValuePair("_TRANID", "AA011_001"));
		params.add(new BasicNameValuePair("_TARGET", "MUFGpop_syokai"));
		params.add(new BasicNameValuePair("_FRAMID", ""));
		params.add(new BasicNameValuePair("_TARGETWINID", ""));
		params.add(p.getNameValuePair("_LUID"));
		params.add(p.getNameValuePair("_SENDTS"));
		params.add(p.getNameValuePair("_PAGEID"));
		params.add(p.getNameValuePair("_WINID"));
		params.add(p.getNameValuePair("_SUBINDEX"));
	
		return params;
	}

	@Override
	protected DocumentChecker getChecker() {
		return checker;
	}
}